package com.gopay.bis.ceb.expay.impl;

import com.gopay.bis.ceb.expay.operation.CebExPayDataSubmit;
import com.gopay.bis.ceb.expay.operation.CebExPayParseData;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.ExPayBaseMessage;
import com.gopay.common.domain.bank.ceb.expay.CebExPayMessage;
import com.gopay.common.domain.bank.ceb.expay.res.CebExpaySuitNSOQRes;
import com.gopay.common.domain.bank.ceb.expay.res.CebExpaySuitNSQRes;
import com.gopay.common.domain.bank.ceb.expay.res.CebExpaySuitPPRes;
import com.gopay.common.domain.bank.ceb.expay.res.CebExpaySuitQSCRes;
import com.gopay.common.domain.bank.ceb.expay.res.CebExpaySuitQUSRes;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.ExPayService;

/**
 * 
 * @CebExPayBankServiceImpl.java
 * @author lilili
 * @2016-3-24 下午5:32:22 www.gopay.com.cn Inc.All rights reserved.
 */
public class CebExPayBankServiceImpl implements ExPayService {

    private ICertHelper cebExPayCertHelper;

    private CebExPayDataSubmit cebExPayDataSubmit;

    private CebExPayParseData cebExPayParseData;

    @Override
    public ExPayBaseMessage sign(BaseMessage baseMsg) throws GopayException {
        return null;
    }

    @Override
    public Object certification(BaseMessage baseMsg) throws GopayException {
        CebExPayMessage msg = (CebExPayMessage) baseMsg;
        String signMsg = cebExPayCertHelper.sign(msg);
        //Object verRes = cebExPayDataSubmit.submitData(signMsg.toString(),msg.getPayUrl());
        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        boolean isVerify = (Boolean) cebExPayCertHelper.verify(msg);
        CebExpaySuitQUSRes messageRes = (CebExpaySuitQUSRes) cebExPayParseData.parseQUSRes(verRes);
        if (isVerify) {
            messageRes.setSuccess(true);
        }
        return messageRes;
    }

    @Override
    public ExPayBaseMessage payment(BaseMessage baseMsg) throws GopayException {        
        CebExPayMessage msg = (CebExPayMessage) baseMsg;
        String signMsg = cebExPayCertHelper.sign(msg);
//        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString(),msg.getPayUrl());
        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        boolean isVerify = (Boolean) cebExPayCertHelper.verify(msg);
        CebExpaySuitPPRes messageRes = (CebExpaySuitPPRes) cebExPayParseData.parsePPRes(verRes);
        if (isVerify) {
            messageRes.setSuccess(true);
        }
        return messageRes;
    }

    @Override
    public ExPayBaseMessage queryOrder(BaseMessage baseMsg) throws GopayException {        
        CebExPayMessage msg = (CebExPayMessage) baseMsg;
        String signMsg = cebExPayCertHelper.sign(msg);
//        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString(),msg.getPayUrl());
        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        boolean isVerify = (Boolean) cebExPayCertHelper.verify(msg);
        CebExpaySuitNSOQRes messageRes = (CebExpaySuitNSOQRes) cebExPayParseData.parseSoqRes(verRes);
        if (isVerify) {
            messageRes.setSuccess(true);
        }
        return messageRes;
    }

    @Override
    public ExPayBaseMessage verify(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ExPayBaseMessage treatyQuery(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ExPayBaseMessage cancel(BaseMessage baseMsg) throws GopayException {
        CebExPayMessage msg = (CebExPayMessage) baseMsg;
        String signMsg = cebExPayCertHelper.sign(msg);
//        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString(),msg.getPayUrl());
        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        boolean isVerify = (Boolean) cebExPayCertHelper.verify(msg);
        CebExpaySuitQSCRes messageRes = (CebExpaySuitQSCRes) cebExPayParseData.parseQSCRes(verRes);
        if (isVerify) {
            messageRes.setSuccess(true);
        }
        return messageRes;
    }
    
    @Override
    public Object signQuery(BaseMessage baseMsg) throws GopayException {
        CebExPayMessage msg = (CebExPayMessage) baseMsg;
        String signMsg = cebExPayCertHelper.sign(msg);
//        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString(),msg.getPayUrl());
        Object verRes = cebExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        boolean isVerify = (Boolean) cebExPayCertHelper.verify(msg);
        CebExpaySuitNSQRes messageRes = (CebExpaySuitNSQRes) cebExPayParseData.parseNSQRes(verRes);
        if (isVerify) {
            messageRes.setSuccess(true);
        }
        return messageRes;
    }

    @Override
    public ExPayBaseMessage refund(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object sendSms(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object checkSms(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object queryCvn(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    public void setCebExPayCertHelper(ICertHelper cebExPayCertHelper) {
        this.cebExPayCertHelper = cebExPayCertHelper;
    }

    public void setCebExPayDataSubmit(CebExPayDataSubmit cebExPayDataSubmit) {
        this.cebExPayDataSubmit = cebExPayDataSubmit;
    }

    public CebExPayParseData getCebExPayParseData() {
        return cebExPayParseData;
    }

    public void setCebExPayParseData(CebExPayParseData cebExPayParseData) {
        this.cebExPayParseData = cebExPayParseData;
    }



}
